package com.roncoo.education.api;

import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
import com.roncoo.education.api.request.RegistrationRequest;
import com.roncoo.education.db.entity.Registration;
import com.roncoo.education.db.service.RegistrationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/admin")
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class RegistrationAdminController {

    @Resource
    private RegistrationService registrationService;

    @PostMapping("/getRegisPage")
    public String getRegisPage(@Valid @RequestBody RegistrationRequest req){
        PageInfo<Registration> pageInfo = registrationService.getRegisPages(req);
        return JSONUtil.toJsonStr(pageInfo);
    }

    @GetMapping("/getRegis")
    public String getRegisDetail(Long id){
        Registration news = registrationService.getRegisById(id);
        return JSONUtil.toJsonStr(news);
    }
}
